<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 让用户输入五个有效年龄
        let arr = []
        while(arr.length<5) {
            let age = +prompt(`请输入第${arr.length+1}个有效年龄`)
            if (age > 0 && age < 100){
                arr.push(age)
            }else{
               alert('请输入有效年龄')
            }
       }
       console.log(arr);
    //    成年人年龄
       for(let i =0; i<arr.length;i++){
        if(arr[i]>=18){
            console.log(arr[i]);
        }
       }
    //    总年龄
       let sum=0
       for(let i =0; i<arr.length;i++){
       sum+=arr[i]
       }
       console.log(sum);
    //    平均年龄
       console.log(sum/arr.length);

// 最大，最小年龄
       let max=arr[0]
       let min=arr[0]
       for(let i =0; i<arr.length;i++){
        if(max>arr[i]){
            max=arr[i]
        }else if(min<arr[i]){
            min=arr[i]
        }
       }
       console.log(max,min);
    </script>
</body>

</html>